package com.edu.zju.scs.panacea.mapper.plan;

import com.edu.zju.scs.panacea.entity.plan.Industry;
import com.edu.zju.scs.panacea.entity.resource.Loc;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: Yue Liang
 * @Date: 2018-12-24 10:25
 */
@Repository
public interface IndustryMapper {
    @Select("SELECT * FROM plan_industry WHERE id = #{id}")
    @Results(id="industryMap", value={
            @Result(id=true,property="id",column="id"),
            @Result(property="name",column="name"),
            @Result(property="qualifications",column="qualifications", typeHandler = com.edu.zju.scs.panacea.utils.JsonTypeHandler.class)})
    Industry selectIndustry(Long id);


    @Select("SELECT * FROM plan_industry")
    @ResultMap(value = "industryMap")
    List<Industry> selectAllIndustry();

    @Delete("DELETE FROM plan_industry where id = #{id}")
    long deleteIndustry(Long id);

    @Insert("INSERT INTO plan_industry(name, qualifications) VALUES (#{name}, #{qualifications, typeHandler=com.edu.zju.scs.panacea.utils.JsonTypeHandler})")
    @Options(useGeneratedKeys=true)
    long insertIndustry(Industry industry);

    @Update({ "update plan_industry set name = #{name}, qualifications = #{qualifications, typeHandler=com.edu.zju.scs.panacea.utils.JsonTypeHandler} where id = #{id}" })
    long updateIndustry(Industry industry);

}
